package com.jxw.launcher.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.v4.internal.view.SupportMenu;
import android.util.AttributeSet;
import android.view.View;
import com.jxw.launcher.R;

/* loaded from: classes.dex */
public class BatteryViewx extends View {
    private int height;
    private int mColor;
    private int mPower;
    private int orientation;
    private int width;

    public BatteryViewx(Context context) {
        super(context);
        this.mPower = 100;
    }

    public BatteryViewx(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mPower = 100;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.Battery);
        this.mColor = obtainStyledAttributes.getColor(0, -1);
        this.orientation = obtainStyledAttributes.getInt(1, 0);
        this.mPower = obtainStyledAttributes.getInt(2, 100);
        this.width = getMeasuredWidth();
        this.height = getMeasuredHeight();
        obtainStyledAttributes.recycle();
    }

    @Override // android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        this.width = getMeasuredWidth();
        this.height = getMeasuredHeight();
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (this.orientation == 0) {
            drawHorizontalBattery(canvas);
        } else {
            drawVerticalBattery(canvas);
        }
    }

    private void drawHorizontalBattery(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(this.mColor);
        paint.setStyle(Paint.Style.STROKE);
        float f = this.width / 20.0f;
        float f2 = f / 2.0f;
        paint.setStrokeWidth(f);
        RectF rectF = new RectF(f2, f2, (this.width - f) - f2, this.height - f2);
        paint.setColor(-16777216);
        canvas.drawRect(rectF, paint);
        paint.setStrokeWidth(0.0f);
        paint.setStyle(Paint.Style.FILL);
        RectF rectF2 = new RectF(f, f, ((this.width - (2.0f * f)) * this.mPower) / 100.0f, this.height - f);
        if (this.mPower < 30) {
            paint.setColor(SupportMenu.CATEGORY_MASK);
        }
        int i = this.mPower;
        if (i >= 30 && i < 50) {
            paint.setColor(-16776961);
        }
        if (this.mPower >= 50) {
            paint.setColor(-16711936);
        }
        canvas.drawRect(rectF2, paint);
        int i2 = this.width;
        float f3 = i2 - f;
        int i3 = this.height;
        RectF rectF3 = new RectF(f3, i3 * 0.25f, i2, i3 * 0.75f);
        paint.setColor(-16777216);
        canvas.drawRect(rectF3, paint);
    }

    private void drawVerticalBattery(Canvas canvas) {
        int i;
        int i2;
        Paint paint = new Paint();
        paint.setColor(this.mColor);
        paint.setStyle(Paint.Style.STROKE);
        float f = this.height / 20.0f;
        float f2 = f / 2.0f;
        paint.setStrokeWidth(f);
        float f3 = (int) (0.5f + f);
        canvas.drawRect(new RectF(f2, f3 + f2, this.width - f2, this.height - f2), paint);
        paint.setStrokeWidth(0.0f);
        RectF rectF = new RectF(f, f3 + f + ((((i2 - i) - f) * (100 - this.mPower)) / 100.0f), this.width - f, this.height - f);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(rectF, paint);
        int i3 = this.width;
        canvas.drawRect(new RectF(i3 / 4.0f, 0.0f, i3 * 0.75f, f3), paint);
    }

    public void setPower(int i) {
        this.mPower = i;
        if (this.mPower < 0) {
            this.mPower = 100;
        }
        invalidate();
    }

    public void setColor(int i) {
        this.mColor = i;
        invalidate();
    }

    public int getPower() {
        return this.mPower;
    }
}
